//
//  NetworkRequestModel.m
//  IPhoneX适配
//
//  Created by 训网高 on 2018/5/3.
//  Copyright © 2018年 训网高. All rights reserved.
//

#import "NetworkRequestModel.h"

@implementation NetworkRequestModel

/*! 为单例对象创建的静态实例，置为nil，因为对象的唯一性，必须是static类型 */
static NetworkRequestModel *networkRequestModel = nil;
+ (instancetype)shareNetworkRequestModel {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        networkRequestModel = [[super allocWithZone:NULL] init];
    });
    return networkRequestModel;
}
/**
 *  重写allocWithZone方法，保证alloc或者init创建的实例不会产生新实例，因为该类覆盖了allocWithZone方法，所以只能通过其父类分配内存，即[super allocWithZone]
 *
 */
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    return [NetworkRequestModel shareNetworkRequestModel];
}

//+ (id)copyWithZone:(NSZone *)zone {
//    return [self shareNetworkRequestModel];
//}
//+ (id)mutableCopyWithZone:(NSZone *)zone {
//    return [self shareNetworkRequestModel];
//}

-(id) copyWithZone:(NSZone *)zone
{
    return [NetworkRequestModel shareNetworkRequestModel] ;
}

-(id) mutablecopyWithZone:(NSZone *)zone
{
    return [NetworkRequestModel shareNetworkRequestModel];

}

#pragma mark ---- 请求数据的接口
/**
 登录
 */
- (void)loginWithParams:(NSDictionary *)params WithUrlString:(NSString *)url resultDic:(void (^)(GXResponse *result))dic {
    [[GXHttpsHandle newInstance] call:HTTPMethod_POST URLString:url parameters:params callback:^(GXResponse *result) {
        DLog(@"%@",result);
        if (result.isSuccess) {
            //RCToken
            [GXUserModel shareInstance].RCToken = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"token"]];
            //isLogin
            [GXUserModel shareInstance].isLogined = YES;
            //token
            [GXUserModel shareInstance].token = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"token"]];
            //user_id
            [GXUserModel shareInstance].user_id = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"os_info"][@"user_id"]];
            //ID
            [GXUserModel shareInstance].ID = [NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
            //sessionid
            [GXUserModel shareInstance].sessionid = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sid"]];
            //userName
            [GXUserModel shareInstance].userName = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"]];
            //password
            //nikName
            [GXUserModel shareInstance].nikName = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"nick_name"]];
            //sex
            [GXUserModel shareInstance].sex =[NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"sendData"][@"sex"] intValue]] ;
            //job
            [GXUserModel shareInstance].job = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"job"]];
            //email
            [GXUserModel shareInstance].email = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"email"]];
            //address
            [GXUserModel shareInstance].address =[NSString stringWithFormat:@"%@ %@",result.result[@"data"][@"sendData"][@"sendData"][@"province"],result.result[@"data"][@"sendData"][@"sendData"][@"city"]];
            //hobby
            //birthday
            //cellPhone
            [GXUserModel shareInstance].cellphone = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"]];
            //remark
            [GXUserModel shareInstance].remark = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"remark"]];
            //headUrl
            [GXUserModel shareInstance].headUrl = [NSString stringWithFormat:@"%@%@%@",GX_IMAGE_URL,result.result[@"data"][@"sendData"][@"sendData"][@"save_path"],result.result[@"data"][@"sendData"][@"sendData"][@"automatic_file_name"]];
            //fileUserIcon
            //province
            //city
            //headImageData
            //fileIdArr
            //uidString
            //bakString
            [GXUserModel shareInstance].bakString = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"bak"]];
            //loginType
            //        [GXUserModel shareInstance].loginType = loginType;
            //registration
            [GXUserModel shareInstance].registration = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"registration"]];
            //role_num
            [GXUserModel shareInstance].role_num = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"role_num"]];
            //customerGroupId
            [GXUserModel shareInstance].customerGroupId = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"customer_group_id"]];
            [GXUserModel saveLoginUserInfo];
        }
        if (dic) {
            dic(result);
        }
    }];
}





@end
